package com.mobile.navigationlearn;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.runner.RunWith;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
//    @Test
//    public void useAppContext() {
//        // Context of the app under test.
//        Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
//        assertEquals("com.mobile.navigationlearn", appContext.getPackageName());
//    }
//    private AndroidDriver<AndroidElement> driver;
//    @Before
//    public void init() {
//        File classpathRoot = new File(System.getProperty("user.dir"));
//        // 获取apps文件，前面测试应用所存放的目录
//        File appDir = new File(classpathRoot, "/apps/");
//        // 获取apk文件
//        File app = new File(appDir, "app.apk");
//        DesiredCapabilities capabilities = new DesiredCapabilities();
//        capabilities.setCapability("platformName","Android");
//        // 系统平台版本
//        capabilities.setCapability("platformVersion", "10");
//        // 设备名，这里是模拟器的设备名
//        capabilities.setCapability("deviceName", "ONEPLUS_A6000");
//        capabilities.setCapability("app", app.getAbsolutePath());
//        // 设置被测应用包名
//        capabilities.setCapability("appPackage", "com.mobile.navigationlearn");
//        // app的入口启动activity
//        capabilities.setCapability("appActivity", ".MainActivity");
//        // 连接appium启动相应app
//        try {
//            driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//        } catch (MalformedURLException e) {
//            e.printStackTrace();
//        }
//        System.out.println("App is launched!");
//    }
////    版权声明：本文为CSDN博主「鱼乐游溪」的原创文章，遵循CC 4.0 BY-SA版权协议，转载请附上原文出处链接及本声明。
////    原文链接：https://blog.csdn.net/yjf611/article/details/104470449
//
//    @Test
//    public void sampleTest() {
//        try {
//            Thread.sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
//        // 点击"同意并继续"
//        WebElement el = driver.findElement(By.xpath(".//*[@text='\u540c\u610f\u5e76\u7ee7\u7eed']"));
//        el.click();
//
//        // 一直点击权限框"允许" 直到没有弹框
//        boolean finished = false;
//        do {
//            try {
//                el = driver.findElement(By.xpath(".//*[@text='\u5141\u8bb8']"));
//                el.click();
//            } catch (NoSuchElementException e) {
//                finished = true;
//            }
//        }while(!finished);
//        System.out.println("App is done!");
//    }
//
//    @After
//    public void end() throws InterruptedException{
//        driver.quit();
//    }
}